#include <iostream>
#include <math.h>

using namespace std;

int d[10000];

int main()
{
	for (int i = 1; i <= 10000; i++)
	{
		d[i] = 0;
		for (int j = 1; j < i; j++)
			if (i % j == 0) d[i] += j;
	}

	int sum = 0;
	for (int i = 1; i <= 10000; i++)
		if (d[i] <= 10000 && d[d[i]] == i && d[i] != i) 
		{
			cout << i << " " << d[i] << endl;
			sum += i;
		}
	
	cout << sum << endl;
}
